package utils;

import com.jme.bounding.BoundingBox;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.shape.Box;
import com.jme.scene.state.MaterialState;
import com.jme.system.DisplaySystem;
import com.jmex.game.state.BasicGameState;

/**
 * This class is for displaying the progress of your current action. Specificly made for the end of mini-game state where
 * it would be useful to tell the user the progress of submitting scores. It is a game state you must enable.
 * Example Usage : End of minigame -> display progress handler -> submit score & update handler -> finish 
 * @author steven sayers
 *
 */
public class ProgressHandler extends BasicGameState {
	//TODO Render the box in the center of the screen
	Box statusBox = new Box("statusBox", new Vector3f(),10,10,10);
	MaterialState ms = DisplaySystem.getDisplaySystem().getRenderer().createMaterialState();
	/**
	 * Set the name of the loading window
	 * @param name (example : Loading : Dome hopper)
	 */
	public ProgressHandler(String name) {
		super(name);
		setStatus(status.RED);
		statusBox.setModelBound(new BoundingBox());
		statusBox.updateModelBound();
		rootNode.attachChild(statusBox);
		rootNode.updateRenderState();
	}
	
	public enum status {
		//Green means done
		GREEN, 
		//Yellow is half way
		YELLOW,
		//Red is just started.
		RED
	}
	
	public void setStatus(Enum<status> setStatus){
		if (setStatus == status.RED){
			statusBox.setDefaultColor(ColorRGBA.red);
			ms.setAmbient(ColorRGBA.red);
			ms.setDiffuse(ColorRGBA.red);
			ms.setEmissive(ColorRGBA.red);
			statusBox.setRenderState(ms);
			statusBox.updateRenderState();
		}
		else if (setStatus == status.YELLOW){
			statusBox.setDefaultColor(ColorRGBA.yellow);
			ms.setAmbient(ColorRGBA.yellow);
			ms.setDiffuse(ColorRGBA.yellow);
			ms.setEmissive(ColorRGBA.yellow);
			statusBox.setRenderState(ms);
			statusBox.updateRenderState();
		}
		else if (setStatus == status.GREEN){
			statusBox.setDefaultColor(ColorRGBA.green);
			ms.setAmbient(ColorRGBA.green);
			ms.setDiffuse(ColorRGBA.green);
			ms.setEmissive(ColorRGBA.green);
			statusBox.setRenderState(ms);
			statusBox.updateRenderState();
		}
	}
}
